// pages/mine/mine.js
let network = require("../../utils/network.js")
let app = getApp();
let url = app.globalData.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dfk:0,
    yfh:0,
    ywc:0,
    ye:'',//余额
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
  },
  // 订单列表
    dalb(){
      var that = this
      let dfk = [];
      let yfh = [];
      let ywc = [];
      network.request({
        url: url + '/AppletsApi/Order/orderList.html',
        data: {
          applet_openid: wx.getStorageSync('applet_openid'),
        },
        method: 'post',
        header: {
          "content-type": "application/x-www-form-urlencoded"
        },
        success: function (res) {
          var data = res.data.data
          // 代付款
          for (var i = 0; i < data.length;i++){
            if (data[i].status == '待支付'){
              dfk.push(data[i])
           }
          }
          that.setData({
            dfk:dfk.length
          })
          // 已发货
          for (var i = 0; i < data.length; i++) {
            if (data[i].status == '已发货') {
              yfh.push(data[i])
            }
          }
          that.setData({
            yfh: yfh.length
          })
          // 已完成
          for (var i = 0; i < data.length; i++) {
            if (data[i].status == '已完成') {
              ywc.push(data[i])
            }
          }
          that.setData({
            ywc: ywc.length
          })
        }
      })
    },
  toOrder:function(e){
    var that = this
    var state = e.currentTarget.dataset.state;
    wx.navigateTo({
      url: '/pages/myorder/myorder?state=' + state,
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.dalb()
    // 余额显示
    network.request({
      url: url + '/AppletsApi/Index/getUserInfo.html',
      data: {
        applet_openid: wx.getStorageSync('applet_openid'),
      },
      method: 'post',
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        that.setData({
          ye: res.data.data.balanceflow
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getPhoneNumber (e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)
  },
  
})